package com.quark;


import org.assertj.core.util.Lists;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author 张高昌
 * @date 2021/12/17 8:46
 * @description: 功能描述
 */
public class SSQStatistics {

    /**
     *
     * @param url 访问路径
     * @return
     */
    public static Document getDocument (String url){
        try {
            //5000是设置连接超时时间，单位ms
            return Jsoup.connect(url).timeout(5000).get();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }


    public static List<Lottery> historyList(){
        List<Lottery> list= Lists.newArrayList();
        //03001代表03年第一期彩票  21036代表21年第36期彩票
        Document doc = getDocument("https://datachart.500.com/ssq/history/newinc/history.php?start=03001&end=21144");
        // 获取目标HTML代码
        Elements trs = doc.select("tbody[id=tdata]").select("tr");
        trs.forEach(e->{
            Elements tds=e.select("td");
            Map<String, String> map = new HashMap<>();
            Lottery lottery = new Lottery();
            lottery.setIssueNumber(tds.get(0).text());
            //指定转换格式
            DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDate date = LocalDate.parse(tds.get(15).text(), fmt);
            lottery.setAwardDate(date);

            lottery.setOne(tds.get(1).text());
            lottery.setTwo(tds.get(2).text());
            lottery.setThree(tds.get(3).text());
            lottery.setFour(tds.get(4).text());
            lottery.setFive(tds.get(5).text());
            lottery.setSix(tds.get(6).text());
            lottery.setSeven(tds.get(7).text());

//            map.put("3", tds.get(3).text());
//            map.put("4", tds.get(4).text());
//            map.put("5", tds.get(5).text());
//            map.put("6", tds.get(6).text());
//            map.put("7", tds.get(7).text());
//            map.put("date", tds.get(15).text());
            list.add(lottery);
//            list.add(tds.get(1).text()+tds.get(2).text()+tds.get(3).text()+tds.get(4).text()+tds.get(5).text()+tds.get(6).text()+tds.get(7).text());
        });
        return list;
    }

    public static void main(String[] args) {
        List<Lottery> strings = historyList();
        List<Lottery> collect = strings.stream().sorted(Comparator.comparing(Lottery::getIssueNumber)).collect(Collectors.toList());
        System.out.println(collect);

//        System.out.println(        DateUtils.formatDate(new Date(),"yyMMdd"));
        System.out.println(Math.pow(33, 6)*16);
    }
}
